using Blog2025.Application.Common;
using Blog2025.Application.Dto;
using Blog2025.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Blog2025.Api.Controllers;
[ApiController]
[Route("api/[controller]")]
public class PermissionController:ControllerBase
{
    private readonly IPermissionAppServices _service;
    public PermissionController(IPermissionAppServices service)
    {
        _service=service;
    }
    // 新增权限
    [HttpPost]
    public async Task<IActionResult> Create(CreatePermissionDto dto)
    {
        await _service.CreatePermissionAsync(dto);
        return Ok("创建成功");
    }
    // 删除权限
    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(Guid id)
    {
        await _service.DeletePermissionAsync(id);
        return Ok("删除成功");
    }
    // 修改权限
    [HttpPut("{id}")]
    public async Task<IActionResult> Update(Guid id ,UpdatePermissionDto dto)
    {
        await _service.UpdatePermissionAsync(id,dto);
        return Ok("修改成功");
    }
    // 获取权限
    [HttpGet]
    public async Task<ApiResult> GetAll(PageRequestDto pageRequestDto)
    {
        var per=await _service.GetAllAsync(pageRequestDto);
        return ApiResult.Success(per);
    }

    [HttpGet("filter")]
    public async Task<IActionResult>  GetFilter()
    {
        var filters=new Dictionary<string,object>
        {
            {"name","审核任务"}
        };
        var res=await _service.GetFilterAsync(filters);
        return Ok(res);
    }

    // 权限详情
    [HttpGet("{id}")]
    public async Task<IActionResult> GetById(Guid id)
    {
        var per=await _service.GetByIdPermission(id);
        return Ok(per);
    }
}